﻿/* 8. Write a program that calculates the greatest common divisor (GCD) of given two numbers. 
 * Use the Euclidean algorithm (find it in Internet). */

// Add Reference to 'System.Numerics'.

using System;
using System.Numerics;

public class GreatestCommonDivisor
{
    public static BigInteger a;
    public static BigInteger b;

    public static void Main()
    {
        DataInput();
        Console.WriteLine("({0}, {1}) = {2}", a, b, GCD());
    }

    public static BigInteger GCD()
    {
        if ((a == 0) || (b == 0))
            return 0;

        if (a < 0)
            a = -a;

        if (b < 0)
            b = -b;

        if (a == b)
            return a;
        else
        {
            do
            {
                if (a < b)
                    b -= a;
                else
                    a -= b;

                if ((a == 1) || (b == 1))
                    return 1;
            } while (a != b);

            return a;
        }
    }

    public static void DataInput()
    {
        do
        {
            Console.Clear();
            Console.Write("a = ");
            if (BigInteger.TryParse(Console.ReadLine(), out a))
            {
                Console.Clear();
                Console.WriteLine("a = {0}", a);
                Console.Write("b = ");
                if (BigInteger.TryParse(Console.ReadLine(), out b))
                    return;
            }
        } while (true);
    }
}